﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moki.Examples.Model;

namespace Moki.Examples
{
    [TestFixture]
    public class MockEvents
    {
        [Test]
        public void SubscribeAndRaise()
        {
            // Arrange
            IPlayer player = Mock.Create<IPlayer>();
            IObserver obs1 = Mock.Create<IObserver>();
            IObserver obs2 = Mock.Create<IObserver>();

            // Subscribes event
            player.PositionChanged += obs1.Update;
            player.PositionChanged += obs2.Update;

            // Act
            Mock.RaiseEvent(() => player.PositionChanged += null, player);

            // Assert
            Mock.VerifyCalled(() => obs1.Update(player));
            Mock.VerifyCalled(() => obs2.Update(player));
        }

        [Test]
        public void RaiseWhenCalled()
        {
            // Arrange
            IPlayer player = Mock.Create<IPlayer>();
            IObserver obs = Mock.Create<IObserver>();

            player.PositionChanged += obs.Update;

            Mock.WhenCalled(() => player.Move(100, 200)).
                Raises(() => player.PositionChanged += null, player);

            // Act
            player.Move(100, 200);

            // Assert
            Mock.VerifyCalled(() => obs.Update(player));
        }
    }
}
